home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-30 | 3.8 KB | 121 lines | [TEXT/MPS ] |
- ;; noweb mode. Relies on tex-support.el.
-
- ;; We assume that the .nw file contains one of the following lines at the top
- ;; % -*-lang : math-*-
- ;; % -*-lang : oot-*-
- ;; % -*-lang : icon-*-
-
-
- (defun noweb-mode ()
- "noweb mode for Lucid Emacs"
- (interactive)
- (setq major-mode 'noweb-mode)
- ; If the file contains a first line like the above, the variable ``lang'' is defined.
- (make-local-variable 'lang)
- (if (equal lang nil)
- (setq mode-name "noweb")
- (setq mode-name (concat (capitalize (prin1-to-string lang)) "-noweb"))
- )
-
- ; nwhome is defined in .emacs.
- (defconst nwlib (concat nwhome "lib/"))
- (defconst nwbin (concat nwhome "bin/"))
- ; Weave and tangle commands.
- (defconst weave (concat nwbin "noweave "))
- (defconst tangle (concat nwbin "notangle -L'#line %-1L \"%F\"%N' "))
- (defconst tangle-nl (concat nwbin "notangle ")) ; With no "line" directives.
- ; Suffixes for tangle output files depend on the buffer-local variable lang.
- (defconst t-suffixes '((math . ".m") (oot . ".t") (icon . ".icn")))
- ; Suffixes for executable files.
- (defconst x-suffixes '((math . ".m") (oot . "") (icon . "")))
-
- (defun nw-make (what)
- (interactive)
- (let* (
- ; The file name.
- (file-name (file-name-nondirectory buffer-file-name))
- ; The base name of the file (without the ".nw" suffix).
- (base-name (substring file-name 0 -3))
- ; t-suff is the suffix of the file where tangle's output should go.
- (t-suff (cdr (assoc lang t-suffixes)))
- ; x-suff is the suffix of the executable.
- (x-suff (cdr (assoc lang x-suffixes)))
- ; The string form of lang.
- (language (prin1-to-string lang))
- ; filter is the full path name to the filter.
- (filter (concat nwlib language ".filter"))
- )
- ; Now we use the ``make-file'' command provided by tex-support.el to do what
- ; we want. A little strange, but it works much better than using compile.el!!
- ; Note: the following ``cond'' defines the arguments to make-file.
- (cond
- ((or (equal what "dvi") (equal what "tex"))
- (setq tex-command (concat "make " base-name "." what)))
- ((equal what "x")
- (setq tex-command (concat "make " base-name x-suff)))
- ((equal what "weave")
- (setq tex-command
- (if (equal lang nil)
- (concat weave " -index " file-name " > " base-name ".tex")
- (concat weave "-autodefs " language " -index -filter " filter " "
- file-name " > " base-name ".tex")
- )
- ))
- ((equal what "tangle")
- (setq tex-command (concat (if (equal lang 'math) tangle-nl tangle) file-name
- " > " base-name t-suff)))
- ((equal what "?")
- (let ((insert-default-directory nil))
- (setq tex-command
- (concat "make " (file-name-nondirectory
- (read-file-name "Make (file name): ")))
- )
- ))
- )
- (make-file)
- )
- )
-
-
- (defconst noweb-menu
- '("noweb"
- ["Make tex" (nw-make "tex") t]
- ["Make dvi" (nw-make "dvi") t]
- ["Make x" (nw-make "x") t]
- "-----"
- ["Weave" (nw-make "weave") t]
- ["Tangle" (nw-make "tangle") t]
- ("More ..." ["Make ..." (nw-make "?") t]
- "-----"
- ["View" (nw-display "view") t]
- ["Print" (nw-display "print") t]
- )
- )
- )
-
-
- (defun install-noweb-menu ()
- "Install a buffer-local noweb menu."
- (interactive)
- (progn
- (set-buffer-menubar (copy-sequence my-default-menubar))
- (add-menu nil "noweb" (cdr noweb-menu))
- )
- )
-
-
- (defun nw-display (how)
- "A modification of \"tex-print\" in tex-support.el"
- (interactive)
- (tex-send-command
- (cond ((equal how "view")
- tex-dvi-view-command)
- ((equal how "print")
- tex-dvi-print-command))
- (concat (substring (file-name-nondirectory buffer-file-name) 0 -3) ".dvi") t)
- )
-
- (run-hooks 'noweb-mode-hook)
-
- )
-